#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 7e4+10;

vector<int> G[N],T[N];

int fa[17][N],siz[N],deg[N],n,dep[N];
queue<int> q;

void dfs(int x){
	siz[x] = 1;
	for(int y : T[x]) dfs(y),siz[x] += siz[y];
}

int lca(int x,int y){
	if(dep[x] < dep[y]) swap(x,y);
	for(int i = 16;i >= 0;i--) if(dep[fa[i][x]] >= dep[y]) x = fa[i][x];
	if(x == y) return x;
	for(int i = 16;i >= 0;i--) if(fa[i][x] ^ fa[i][y]) x = fa[i][x],y = fa[i][y];
	return fa[0][x];
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in;
	for(int i = 1,x;i <= n;i++){
		while(x = in) G[x].pb(i),deg[i]++;
	}
	for(int i = 1;i <= n;i++){
		if(!deg[i]) q.push(i),fa[0][i] = 0;
		else fa[0][i] = -1;
	}
	while(q.size()){
		int x = q.front(); q.pop();
		T[fa[0][x]].pb(x); dep[x] = dep[fa[0][x]] + 1;
		for(int i = 1;i < 17;i++) fa[i][x] = fa[i-1][fa[i-1][x]];
		for(int y : G[x]){
			if(!~fa[0][y]) fa[0][y] = x;
			else fa[0][y] = lca(fa[0][y],x);
			if(!--deg[y]) q.push(y);
		}
	}
	dfs(0);
	for(int i = 1;i <= n;i++) printf("%d\n",siz[i] - 1);
	return 0;
}

